<template>

  <el-form ref="form" :model="Loginform" label-width="80px">
    <el-form-item label="账号">
      <el-input v-model="Loginform.username"></el-input>
    </el-form-item>

    <el-form-item label="密码">
      <el-input type="password" v-model="Loginform.password"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="login">登录</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name:'Login',
  data(){
    return {
      Loginform:{
        username:'admin',
        password:'123456'
      }
    }
  },
  created() {
    // this.login();
  },
  methods:{
    //模拟登录
    async login()
    {
      var _this=this;
      //连接后端传数据
      const { data: res } = await _this.$ajax.post('http://www.caihuay.com.cn/index.php/login/login',{username:this.Loginform.username,password:this.Loginform.password});
      console.log(res);

      console.log(res.msg);
      //登录成功以后  提示信息 message组件
      if(res.code===1)
      {
        this.$msg.success(res.msg);
        //存入session
        window.sessionStorage.setItem('token',res.token);
        //跳转到后台首页面
        this.$router.push('/HelloWorld');
      }
      else
      {
        this.$msg.error(res.msg);
      }
    }
  }
};
</script>
<style>

</style>
